package com.scripts;

import Utilities.Commons;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;
import java.util.List;

/**
 * Created by orlandocampos on 10/3/14.
 */
public class TestGoogle {

    protected static WebDriver wd;
    protected static WebElement searchBar;

    @BeforeClass

    public static void setup(){

        wd = new ChromeDriver();
        wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }

    @Test

    public void Testcase() throws Exception{


        wd.get("http://google.com");
        searchBar = wd.findElement(By.id("gbqfq"));

        searchBar.sendKeys("Pluralsight");

        (wd.findElement(By.id("gbqfb"))).click();

        //-------------- Seleccionar un link de entre muchos, sin ID
        //(wd.findElement(By.xpath("//*[@id='hdtb_msb']/div[4]/a"))).click();
        //--------------
        //List <WebElement> lala =  wd.findElements(By.cssSelector(".q.qs"));
        //lala.get(2).click();
        //--------------


        (wd.findElements(By.cssSelector(".q.qs"))).get(2).click();


        //--------------


        //(wd.findElement(By.xpath("//*[@id='rg_s']/div[1]/a"))).click();
        (wd.findElements(By.cssSelector("#rg_s div"))).get(0).click();

        Commons.wait(Commons.TIMEOUT_5_SECONDS);


        //Para revisar si hay un texto X en el sitio
        wd.getPageSource().contains("X");
    }

    @AfterClass

    public static void teardown()  {

        wd.close();

        wd.quit();

    }
}
